package Before826.datastructure;

public class MidSearch {
    int low;
    int high;
    int mid ;
    public MidSearch(){}
    public int search1(int[] arr , int key ){
        low =0;
        high = arr.length-1;
        mid = (high+low)/2;
        while(arr[mid] != key){
            if(key > arr[mid]){
               low = mid + 1;
            }else if(key < arr[mid]){
                high = mid - 1;
            }
            if(high < low){
                return -1;
            }
            mid = (high + low)/2;
        }
        //返回值为对应key值得下标
        return mid;
    }

}
